/**
 * @author wangj881
 * @date 2024-12-03 9:58
 */
public class L746_2 {

    public static void main(String[] args) {
        int[] cost = {1,100,1,1,1,100,1,1,100,1};
        int i = new Solution().minCostClimbingStairs(cost);
        System.out.println(i);
    }

    static class Solution {
        public int minCostClimbingStairs(int[] cost) {
            int[] dp = new int[cost.length + 1];
            dp[0] = cost[0];
            dp[1] = cost[1];
            for (int i = 2; i < cost.length; i++) {
                dp[i] = Math.min(dp[i - 1] + cost[i], dp[i - 2] + cost[i]);
            }
            int last = dp.length - 1;
            dp[dp.length - 1] = Math.min(dp[last - 1], dp[last - 2]);

            return dp[last];
        }
    }
}
